package org.example.javadt.service;


import jakarta.servlet.http.HttpServletRequest;
import org.example.javadt.entity.Users;
import org.example.javadt.mapperjiekou.usermp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@CrossOrigin(origins = "*", methods = {RequestMethod.GET, RequestMethod.POST})
public class logins {
    //依赖注入
    @Autowired
    private usermp usermp;

    @RequestMapping("/login")

    public int login(HttpServletRequest request) {
        String name = request.getParameter("name");
        String pass = request.getParameter("pass");
        System.out.println(name);
        if (name == null || pass == null) {
            return 0; // 参数缺失，登录失败
        }

        List<Users> users = usermp.selectbynp(name, pass);
        return users.isEmpty() ? 0 : 1;
    }


    @RequestMapping("/zhu")

    public int zhu(HttpServletRequest request) {
        String name = request.getParameter("name");
        String pass = request.getParameter("pass");
        return usermp.zhu(name, pass);
    }

    @RequestMapping("/xiu")

    public int xiu(HttpServletRequest request) {
        String name = request.getParameter("name");
        String pass = request.getParameter("pass");
        return usermp.xiu(name, pass);
    }

    @RequestMapping("/delet")

    public int delet(HttpServletRequest request) {
        String name = request.getParameter("name");
        String pass = request.getParameter("pass");
        return usermp.delete(name, pass);

    }

    @RequestMapping("/ceshi")
    public List<Users> ceshi() {

        return usermp.selectall();

    }

    @RequestMapping("/zhaohui")
    public String zhaohui(HttpServletRequest request) {
        String name = request.getParameter("name");
        System.out.println(name);
        return usermp.selectpas(name);

    }
}
